<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../vue.js"></script>
</head>

<body>
    <div class="app">
        <h1>{{title}}</h1>
        <hr>
        <parent></parent>

    </div>

    <template id="parent">
        <div>
            
            <h1>父元素的数据-{{name}}</h1>
            
        <hr>
        <childone :changeage="changeage"></childone>
        <hr>
        <childtwo ref="two"></childtwo>

        </div>

    </template>

    <template id="childone">
        <div>
            <h3>子元素1-{{name}}-{{age}}</h3>
            <button @click="changeage">点击修改儿子2号的age</button>
        </div>
    </template>

    <template id="childtwo">
        <div>
            <h3>子元素2-{{name}}-{{age}}</h3>
        </div>
    </template>

    <script>
        Vue.component("parent", {
            template: "#parent",
            data() {
                return {
                    name: "不吃鱼的猫",
                    age: 18
                }
            },
            methods: {
                changeage() {
                    this.$refs.two.age += 5
                }
            }

        })
        Vue.component("childone", {
            template: "#childone",
            data() {
                return {
                    name: "我是儿子1号",
                    age: 1
                }
            },
            props: ["changeage"]
        })
        Vue.component("childtwo", {
            template: "#childtwo",
            data() {
                return {
                    name: "我是儿子2号",
                    age: 2
                }
            }

        })
        const vm = new Vue({
            data: {
                title: "兄弟改兄弟通过反向props修改父元素的数据进改子元素的数据"
            }
        }).$mount(".app")
    </script>
</body>

</html>